import request from '@/utils/request'
/**
 * 获取部门
 */
export function getDepartments() {
  return request({
    url: '/company/department'
  })
}

/**
 * 删除部门
 * @param {string} id 部门 id
 */
export function delDepartments(id) {
  return request({
    url: `/company/department/${id}`,
    method: 'DELETE'
  })
}

/**
 * 添加部门
 * @param {object} data 添加的部门对象
 */
export function addDepartments(data) {
  request({
    url: '/company/department',
    method: 'POST',
    data
  })
}

// 获取部门详情
export function getDepartDetail(id) {
  return request({
    url: `/company/department/${id}`
  })
}

export function updateDepartments(formData) {
  return request({
    url: `/company/department/${formData.id}`,
    method: 'PUT',
    data: formData
  })
  // GET => 获取
  // POST => 新增
  // DELETE => 删除
  // PUT => 全量更新（会直接覆盖） => { id: 8 }（传递的直接覆盖右边的） => { id: 9, name: 'ifer', age: 18 }
  // PATCH => 打补丁更新（传谁只会改谁，不会覆盖） => { id: 8 }
}
